package com.lzx.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.lzx.kafka.model.Notify;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Random;

/**
 * @ClassName KafkaController
 * @Author 刘正星
 * @Date 2021/4/20 下午3:07
 * @Description
 */
@Controller
@RequestMapping("/kafka")
public class KafkaSender {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    //发送消息方法
    @RequestMapping("/send")
    @ResponseBody
    public String send(@RequestBody Notify notify) {
        kafkaTemplate.send("YouKeDa","Level", JSON.toJSONString(notify));
        return "success";
    }


 /*   int i;
    @Test
    public void stream(){


        Random random = new Random();
        random.ints(20,10,99).boxed().filter(e->e%2==0).forEach((e)->{
            i++;
            System.out.print(e+",");
            if (i!=0&&i%5==0){
                System.out.println();
            }

        });
    }
*/


}
